
//               File: ClienteDataAdapter
//        Description: Cliente
//             Author: DeKlarit - Language C# - Generator Version 10_1_3-31907 - Specifier Version 10_1_3.31907
//       Program type: Deklarit Business Component
//          Main DBMS: Microsoft SqlServer

namespace DeklaritModel {
   using System;
   using System.Collections;
   using Deklarit.Utils;
   using System.Data;
   using System.Data.SqlClient;
   using System.Data.Common;
   using Deklarit.Data;
   using System.ComponentModel.Design;
   using System.Runtime.Serialization;
   using System.Security.Permissions;
   using System.Data.SqlTypes;
   public partial class ClienteDataAdapter : System.Data.IDataAdapter, IClienteDataAdapter
   {
      private ClienteDataSet ClienteSet ;
      private IDbTransaction daCurrentTransaction ;
      private ClienteDataSet.ClienteRow rowCliente ;
      public ClienteDataAdapter( )
      {
      }

      private void InitializeMembers( )
      {
         ClienteSet = new ClienteDataSet() ;
         this.Initialize( ) ;
         dsDefault = new DataStore( new SqlServer2005Handler( ), "System.Data.SqlClient", DeklaritModel.Configuration.ConnectionString, DeklaritTransaction.TransactionSlotName) ;
      }

      ///  <summary>
      ///   Gets or sets the Transaction object to be used  by  ClienteDataAdapterclasses to
      ///    commit changes to the Database.
      ///  </summary>
      public IDbTransaction Transaction
      {
         get {
            return daCurrentTransaction ;
         }

         set {
            daCurrentTransaction = value ;
         }

      }

      ///  <summary>
      ///   Gets or sets the missing mapping action.
      ///  </summary>
      public MissingMappingAction MissingMappingAction
      {
         get {
            return System.Data.MissingMappingAction.Passthrough ;
         }

         set {
         }

      }

      ///  <summary>
      ///   Gets or sets the missing schema action.
      ///  </summary>
      public MissingSchemaAction MissingSchemaAction
      {
         get {
            return System.Data.MissingSchemaAction.Ignore ;
         }

         set {
         }

      }

      ///  <summary>
      ///   Gets the table mappings.
      ///  </summary>
      public ITableMappingCollection TableMappings
      {
         get {
            System.Data.Common.DataTableMappingCollection tableMaps ;
            tableMaps = new System.Data.Common.DataTableMappingCollection() ;
            return tableMaps ;
         }

      }

      ///  <summary>
      ///   Fills the schema for the datasource.
      ///  </summary>
      ///  <param name="dataSet">DataSet</param>
      ///  <param name="schemaType">Schema type</param>
      public virtual DataTable[] FillSchema( DataSet dataSet ,
                                             SchemaType schemaType )
      {
         DataTable[] dataTables ;
         dataTables = new DataTable[dataSet.Tables.Count]  ;
         dataSet.Tables.CopyTo( dataTables, dataSet.Tables.Count) ;
         return dataTables ;
      }


      ///  <summary>
      ///   (2) Fills the specified Dataset with the record matching ClienteId field(s) of the
      ///    given IDataRecord
      ///  </summary>
      ///  <param name="dataSet">DataSet</param>
      ///  <param name="dataRecord">Data Record</param>
      public virtual int Fill( ClienteDataSet dataSet ,
                               IDataRecord dataRecord )
      {
         return Fill(dataSet, ((short)(dataRecord["ClienteId"]))) ;
      }

      ///  <summary>
      ///   (3) Fills the specified Dataset with the record matching ClienteId field(s) of the
      ///    given DataRow
      ///  </summary>
      ///  <param name="dataSet">DataSet</param>
      ///  <param name="dataRecord">Data Row</param>
      public virtual int Fill( ClienteDataSet dataSet ,
                               DataRow dataRecord )
      {
         return Fill(dataSet, ((short)(dataRecord["ClienteId"]))) ;
      }

      ///  <summary>
      ///   (4) Fills the specified Dataset with the record matching ClienteId, if the record
      ///    is not found , throws an exception.
      ///  </summary>
      ///  <param name="dataSet">DataSet</param>
      ///  <param name="clienteId">Cliente</param>
      public virtual int Fill( ClienteDataSet dataSet ,
                               short clienteId )
      {
         if ( ! FillByClienteId( dataSet, clienteId) )
         {
            throw new ClienteNotFoundException( string.Format(resourceManager.GetString("GXM_inex"), new   object[]  {"Cliente"})) ;
         }
         return 0 ;
      }


      ///  <summary>
      ///   (5) Fills the specified Dataset with the record matching ClienteId in the fillDataParameters
      ///    array, if the array is null, it fills the Dataset loading all records in the table.
      ///
      ///  </summary>
      ///  <param name="dataSet">DataSet</param>
      public virtual int Fill( ClienteDataSet dataSet )
      {
         if ( fillDataParameters != null )
         {
            Fill( dataSet, System.Int16.Parse( fillDataParameters[0].Value.ToString())) ;
         }
         else
         {
            try
            {
               InitializeMembers( ) ;
               connDefault = dsDefault.GetReadWriteConnection( daCurrentTransaction) ;
               ClienteSet = dataSet ;
               LoadChildCliente( 0, -1) ;
               dataSet.AcceptChanges( ) ;
            }
            finally
            {
               this.Cleanup();
            }
         }
         return 0 ;
      }


      ///  <summary>
      ///   (6) Fills the specified dataset filtered by ClienteIdfield(s).
      ///  </summary>
      ///  <param name="dataSet">DataSet</param>
      ///  <param name="clienteId">Cliente</param>
      public virtual bool FillByClienteId( ClienteDataSet dataSet ,
                                           short clienteId )
      {
         InitializeMembers( ) ;
         connDefault = dsDefault.GetReadWriteConnection( daCurrentTransaction) ;
         ClienteSet = dataSet ;
         rowCliente = ClienteSet.Cliente.NewClienteRow() ;
         rowCliente.ClienteId = clienteId ;
         try
         {
            LoadByClienteId( 0, -1) ;
            dataSet.AcceptChanges( ) ;
         }
         finally
         {
            this.Cleanup();
         }
         if ( RcdFound1 == 0 )
         {
            return false ;
         }
         return true ;
      }


      ///  <summary>
      ///   (6) Fills the specified dataset filtered by PaisIdfield(s).
      ///  </summary>
      ///  <param name="dataSet">DataSet</param>
      ///  <param name="paisId">Id Pais</param>
      public virtual int FillByPaisId( ClienteDataSet dataSet ,
                                       short paisId )
      {
         InitializeMembers( ) ;
         connDefault = dsDefault.GetReadWriteConnection( daCurrentTransaction) ;
         ClienteSet = dataSet ;
         rowCliente = ClienteSet.Cliente.NewClienteRow() ;
         rowCliente.PaisId = paisId ;
         try
         {
            LoadByPaisId( 0, -1) ;
            dataSet.AcceptChanges( ) ;
         }
         finally
         {
            this.Cleanup();
         }
         return 0 ;
      }


      ///  <summary>
      ///   (6) Fills a page of up to maxRows rows into the specified dataset filtered by PaisIdfield(s)starting
      ///    at startRow
      ///  </summary>
      ///  <param name="dataSet">DataSet</param>
      ///  <param name="paisId">Id Pais</param>
      ///  <param name="startRow">Starting row</param>
      ///  <param name="maxRows">Max number of rows to load</param>
      public virtual int FillPageByPaisId( ClienteDataSet dataSet ,
                                           short paisId ,
                                           int startRow ,
                                           int maxRows )
      {
         InitializeMembers( ) ;
         connDefault = dsDefault.GetReadWriteConnection( daCurrentTransaction) ;
         ClienteSet = dataSet ;
         rowCliente = ClienteSet.Cliente.NewClienteRow() ;
         rowCliente.PaisId = paisId ;
         try
         {
            LoadByPaisId( startRow, maxRows) ;
            dataSet.AcceptChanges( ) ;
         }
         finally
         {
            this.Cleanup();
         }
         return 0 ;
      }


      ///  <summary>
      ///   (9) Gets the record count filtered by PaisIdfield(s).
      ///  </summary>
      ///  <param name="paisId">Id Pais</param>
      public virtual int GetRecordCountByPaisId( short paisId )
      {
         int m_Count ;
         try
         {
            InitializeMembers( ) ;
            m_Count = GetInternalRecordCountByPaisId( paisId ) ;
         }
         finally
         {
            this.Cleanup();
         }
         return m_Count ;
      }

      private int GetInternalRecordCountByPaisId( short paisId )
      {
         connDefault = dsDefault.GetReadWriteConnection( daCurrentTransaction) ;
         cmCLIENTESELECT1 = connDefault.GetCommand("SELECT COUNT(*) FROM [Cliente] WITH (NOLOCK) WHERE [PaisId] = @PaisId ", false) ;
         if ( cmCLIENTESELECT1.IDbCommand.Parameters.Count == 0 )
         {
            cmCLIENTESELECT1.IDbCommand.Parameters.Add(  dsDefault.GetDbParameter( "@PaisId", System.Data.DbType.Int16));
         }
         cmCLIENTESELECT1.SetParameter(0, paisId);
         CLIENTESELECT1 = cmCLIENTESELECT1.FetchData() ;
         recordCount = ( ( CLIENTESELECT1.IsDBNull(0) )  ? (int)(0) : CLIENTESELECT1.GetInt32(0) ) ;
         CLIENTESELECT1.Close();
         return recordCount ;
      }

      ///  <summary>
      ///   (8) Fills the specified dataset with the record matching ClienteId in the the fillDataParameters
      ///    array, if the array is null, it fills the Dataset loading all records in the table.
      ///
      ///  </summary>
      ///  <param name="dataSet">DataSet</param>
      public virtual int Fill( DataSet dataSet )
      {
         ClienteSet = dataSet as ClienteDataSet ;
         if ( ClienteSet != null )
         {
            return Fill( ClienteSet) ;
         }
         else
         {
            ClienteSet = new ClienteDataSet() ;
            Fill( ClienteSet) ;
            dataSet.Merge( ClienteSet) ;
            return 0 ;
         }
      }

      ///  <summary>
      ///   (11) Fills a page of up to maxRows rows into the specified dataset starting at startRow
      ///
      ///  </summary>
      ///  <param name="dataSet">DataSet</param>
      ///  <param name="startRow">Starting row</param>
      ///  <param name="maxRows">Max number of rows to load</param>
      public virtual int FillPage( ClienteDataSet dataSet ,
                                   int startRow ,
                                   int maxRows )
      {
         InitializeMembers( ) ;
         connDefault = dsDefault.GetReadWriteConnection( daCurrentTransaction) ;
         ClienteSet = dataSet ;
         try
         {
            LoadChildCliente( startRow, maxRows) ;
            dataSet.AcceptChanges( ) ;
         }
         finally
         {
            this.Cleanup();
         }
         return 0 ;
      }


      ///  <summary>
      ///   (9) Gets the total record count.
      ///  </summary>
      public virtual int GetRecordCount( )
      {
         int m_Count ;
         try
         {
            InitializeMembers( ) ;
            m_Count = GetInternalRecordCount(  ) ;
         }
         finally
         {
            this.Cleanup();
         }
         return m_Count ;
      }

      private int GetInternalRecordCount( )
      {
         connDefault = dsDefault.GetReadWriteConnection( daCurrentTransaction) ;
         cmCLIENTESELECT2 = connDefault.GetCommand("SELECT COUNT(*) FROM [Cliente] WITH (NOLOCK) ", false) ;
         CLIENTESELECT2 = cmCLIENTESELECT2.FetchData() ;
         recordCount = ( ( CLIENTESELECT2.IsDBNull(0) )  ? (int)(0) : CLIENTESELECT2.GetInt32(0) ) ;
         CLIENTESELECT2.Close();
         return recordCount ;
      }

      ///  <summary>
      ///   Gets the fill parameters array.
      ///  </summary>
      public virtual IDataParameter[] GetFillParameters( )
      {
         if ( fillDataParameters == null )
         {
            DbProviderFactory factory = System.Data.Common.DbProviderFactories.GetFactory( "System.Data.SqlClient") ;
            DbParameter parm0ClienteId ;
            parm0ClienteId = factory.CreateParameter() ;
            parm0ClienteId.ParameterName = "ClienteId" ;
            parm0ClienteId.DbType = System.Data.DbType.Int16 ;
            fillDataParameters = new  DbParameter[]  {parm0ClienteId} ;
         }
         return fillDataParameters ;
      }

      private DbParameter[] fillDataParameters ;

      ///  <summary>
      ///   Inserts, Updates or Deletes records from the specified ClienteDataSet object.
      ///  </summary>
      ///  <param name="dataSet">DataSet</param>
      public virtual int Update( DataSet dataSet )
      {
         InitializeMembers( ) ;
         ClienteSet = dataSet as ClienteDataSet ;
         connDefault = dsDefault.GetReadWriteConnection( daCurrentTransaction) ;
         if ( ClienteSet != null )
         {
            try
            {
               connDefault.BeginTransaction();
               foreach( ClienteDataSet.ClienteRow row in ClienteSet.Cliente )
               {
                  rowCliente = row ;
                  if ( Deklarit.Data.Helpers.IsRowChanged(rowCliente) )
                  {
                     ReadRowCliente( ) ;
                     if ( rowCliente.RowState == System.Data.DataRowState.Added )
                     {
                        InsertCliente( ) ;
                     }
                     else
                     {
                        if ( _Gxremove )
                        {
                           Delete( ) ;
                        }
                        else
                        {
                           UpdateCliente( ) ;
                        }
                     }
                  }
               }

               dataSet.AcceptChanges( ) ;
               connDefault.Commit();
            }
            catch ( Exception  )
            {
               connDefault.Rollback();
               throw  ;
            }
            finally
            {
               this.Cleanup();
            }
         }
         else
         {
            throw new System.ArgumentException( string.Format(resourceManager.GetString("GXM_nulldset"), new   object[]  {})) ;
         }
         return 0 ;
      }

      private void LoadRowCliente( )
      {
         AddRowCliente( ) ;
      }

      private void ReadRowCliente( )
      {
         Gx_mode = Deklarit.Utils.Mode.FromRowState(rowCliente.RowState) ;
         if ( rowCliente.RowState != System.Data.DataRowState.Deleted )
         {
            rowCliente["ClienteBirthday"] = Deklarit.Utils.DateTimeUtil.ResetTimeObject(rowCliente["ClienteBirthday"]) ;
         }
         if ( rowCliente.RowState != System.Data.DataRowState.Added )
         {
            m__ClienteNameOriginal = rowCliente["ClienteName", System.Data.DataRowVersion.Original] ;
            m__ClienteGenderOriginal = rowCliente["ClienteGender", System.Data.DataRowVersion.Original] ;
            m__ClienteAgeOriginal = rowCliente["ClienteAge", System.Data.DataRowVersion.Original] ;
            m__ClienteBirthdayOriginal = rowCliente["ClienteBirthday", System.Data.DataRowVersion.Original] ;
            m__ClienteIsActiveOriginal = rowCliente["ClienteIsActive", System.Data.DataRowVersion.Original] ;
            m__ClientePictureOriginal = rowCliente["ClientePicture", System.Data.DataRowVersion.Original] ;
            m__PaisIdOriginal = rowCliente["PaisId", System.Data.DataRowVersion.Original] ;
         }
         else
         {
            m__ClienteNameOriginal = rowCliente["ClienteName"] ;
            m__ClienteGenderOriginal = rowCliente["ClienteGender"] ;
            m__ClienteAgeOriginal = rowCliente["ClienteAge"] ;
            m__ClienteBirthdayOriginal = rowCliente["ClienteBirthday"] ;
            m__ClienteIsActiveOriginal = rowCliente["ClienteIsActive"] ;
            m__ClientePictureOriginal = rowCliente["ClientePicture"] ;
            m__PaisIdOriginal = rowCliente["PaisId"] ;
         }
         _Gxremove = (bool)((rowCliente.RowState==System.Data.DataRowState.Deleted)) ;
         if ( _Gxremove )
         {
            rowCliente = ((ClienteDataSet.ClienteRow)(Deklarit.Utils.DataSetUtil.CloneOriginalDataRow(rowCliente)));
         }
      }

      private void LoadCliente( )
      {
          IDataReader PAISSELECT1 ;
          ReadWriteCommand cmPAISSELECT1 ;
         cmPAISSELECT1 = connDefault.GetCommand("SELECT [PaisNombre] FROM [Pais] WITH (NOLOCK) WHERE [PaisId] = @PaisId ", false) ;
         if ( cmPAISSELECT1.IDbCommand.Parameters.Count == 0 )
         {
            cmPAISSELECT1.IDbCommand.Parameters.Add(  dsDefault.GetDbParameter( "@PaisId", System.Data.DbType.Int16));
         }
         cmPAISSELECT1.SetParameter(0, rowCliente["PaisId"]);
         PAISSELECT1 = cmPAISSELECT1.FetchData() ;
         if ( cmPAISSELECT1.HasMoreRows )
         {
            rowCliente["PaisNombre"] = dsDefault.Db.GetString(PAISSELECT1, 0) ;
         }
         PAISSELECT1.Close();
      }

      private void CheckExtendedTableCliente( )
      {
          IDataReader PAISSELECT2 ;
          ReadWriteCommand cmPAISSELECT2 ;
         if ( !  System.Enum.IsDefined(typeof(GenderEnum),((int)(((short)(rowCliente["ClienteGender"]))))) )
         {
            throw new ClienteGenderInvalidValue( "Invalid Sexo Value") ;
         }
         cmPAISSELECT2 = connDefault.GetCommand("SELECT [PaisNombre] FROM [Pais] WITH (NOLOCK) WHERE [PaisId] = @PaisId ", false) ;
         if ( cmPAISSELECT2.IDbCommand.Parameters.Count == 0 )
         {
            cmPAISSELECT2.IDbCommand.Parameters.Add(  dsDefault.GetDbParameter( "@PaisId", System.Data.DbType.Int16));
         }
         cmPAISSELECT2.SetParameter(0, rowCliente["PaisId"]);
         PAISSELECT2 = cmPAISSELECT2.FetchData() ;
         if ( !cmPAISSELECT2.HasMoreRows )
         {
            PAISSELECT2.Close();
            throw new PaisForeignKeyNotFoundException( string.Format(resourceManager.GetString("GXM_inex"), new   object[]  {"Pais"})) ;
         }
         rowCliente["PaisNombre"] = dsDefault.Db.GetString(PAISSELECT2, 0) ;
         PAISSELECT2.Close();
      }

      private void GetByPrimaryKey( )
      {
          IDataReader CLIENTESELECT3 ;
          ReadWriteCommand cmCLIENTESELECT3 ;
         cmCLIENTESELECT3 = connDefault.GetCommand("SELECT [ClienteId], [ClienteName], [ClienteGender], [ClienteAge], [ClienteBirthday], [ClienteIsActive], [PaisId], [ClientePicture] FROM [Cliente] WITH (NOLOCK) WHERE [ClienteId] = @ClienteId ", false) ;
         if ( cmCLIENTESELECT3.IDbCommand.Parameters.Count == 0 )
         {
            cmCLIENTESELECT3.IDbCommand.Parameters.Add(  dsDefault.GetDbParameter( "@ClienteId", System.Data.DbType.Int16));
         }
         cmCLIENTESELECT3.SetParameter(0, rowCliente["ClienteId"]);
         CLIENTESELECT3 = cmCLIENTESELECT3.FetchData() ;
         if ( cmCLIENTESELECT3.HasMoreRows )
         {
            RcdFound1 = 1 ;
            rowCliente["ClienteId"] = dsDefault.Db.GetInt16(CLIENTESELECT3, 0) ;
            rowCliente["ClienteName"] = dsDefault.Db.GetString(CLIENTESELECT3, 1) ;
            rowCliente["ClienteGender"] = dsDefault.Db.GetInt16(CLIENTESELECT3, 2) ;
            rowCliente["ClienteAge"] = dsDefault.Db.GetInt16(CLIENTESELECT3, 3) ;
            rowCliente["ClienteBirthday"] = dsDefault.Db.GetDateTime(CLIENTESELECT3, 4) ;
            rowCliente["ClienteIsActive"] = dsDefault.Db.GetBoolean(CLIENTESELECT3, 5) ;
            rowCliente["PaisId"] = dsDefault.Db.GetInt16(CLIENTESELECT3, 6) ;
            rowCliente["ClientePicture"] = dsDefault.Db.GetBinary(CLIENTESELECT3, 7) ;
            sMode1 = Gx_mode ;
            Gx_mode = Mode.Display ;
            LoadCliente( ) ;
            Gx_mode = sMode1 ;
         }
         else
         {
            RcdFound1 = 0 ;
         }
         CLIENTESELECT3.Close();
      }

      private void CheckOptimisticConcurrencyCliente( )
      {
          ReadWriteCommand cmCLIENTESELECT4 ;
         if ( Gx_mode != Mode.Insert )
         {
            cmCLIENTESELECT4 = connDefault.GetCommand("SELECT [ClienteId], [ClienteName], [ClienteGender], [ClienteAge], [ClienteBirthday], [ClienteIsActive], [PaisId], [ClientePicture] FROM [Cliente] WITH (UPDLOCK) WHERE [ClienteId] = @ClienteId ", false) ;
            if ( cmCLIENTESELECT4.IDbCommand.Parameters.Count == 0 )
            {
               cmCLIENTESELECT4.IDbCommand.Parameters.Add(  dsDefault.GetDbParameter( "@ClienteId", System.Data.DbType.Int16));
            }
            cmCLIENTESELECT4.SetParameter(0, rowCliente["ClienteId"]);
            CLIENTESELECT4 = cmCLIENTESELECT4.FetchData() ;
            if ( cmCLIENTESELECT4.Locked )
            {
               CLIENTESELECT4.Close();
               throw new ClienteDataLockedException( string.Format(resourceManager.GetString("GXM_lock"), new   object[]  {"Cliente"})) ;
            }
            _Condition = false ;
            if ( !cmCLIENTESELECT4.HasMoreRows || ( ! StringUtil.ObjectStringEquals(m__ClienteNameOriginal,dsDefault.Db.GetString(CLIENTESELECT4, 1)) ) || ( ! m__ClienteGenderOriginal.Equals(dsDefault.Db.GetInt16(CLIENTESELECT4, 2)) ) || ( ! m__ClienteAgeOriginal.Equals(dsDefault.Db.GetInt16(CLIENTESELECT4, 3)) ) || ( ! DateTimeUtil.ObjectDateEquals(m__ClienteBirthdayOriginal,dsDefault.Db.GetDateTime(CLIENTESELECT4, 4)) ) || ( ! m__ClienteIsActiveOriginal.Equals(dsDefault.Db.GetBoolean(CLIENTESELECT4, 5)) ) )
            {
               _Condition = true ;
            }
            if ( _Condition || ! BlobUtil.IsEqual( m__ClientePictureOriginal , dsDefault.Db.GetBinary(CLIENTESELECT4, 7) ) || ( ! m__PaisIdOriginal.Equals(dsDefault.Db.GetInt16(CLIENTESELECT4, 6)) ) )
            {
               CLIENTESELECT4.Close();
               throw new ClienteDataChangedException( string.Format(resourceManager.GetString("GXM_waschg"), new   object[]  {"Cliente"})) ;
            }
            CLIENTESELECT4.Close();
         }
      }

      private void InsertCliente( )
      {
          IDataReader CLIENTEINSERT1 ;
          ReadWriteCommand cmCLIENTEINSERT1 ;
         CheckExtendedTableCliente( ) ;
         CheckOptimisticConcurrencyCliente( ) ;
         AfterConfirmCliente( ) ;
         cmCLIENTEINSERT1 = connDefault.GetCommand("INSERT INTO [Cliente] ([ClienteName], [ClienteGender], [ClienteAge], [ClienteBirthday], [ClienteIsActive], [ClientePicture], [PaisId]) VALUES (@ClienteName, @ClienteGender, @ClienteAge, @ClienteBirthday, @ClienteIsActive, @ClientePicture, @PaisId); SELECT SCOPE_IDENTITY()", false) ;
         if ( cmCLIENTEINSERT1.IDbCommand.Parameters.Count == 0 )
         {
            cmCLIENTEINSERT1.IDbCommand.Parameters.Add(  dsDefault.GetDbParameter( "@ClienteName", System.Data.DbType.AnsiStringFixedLength,20));
            cmCLIENTEINSERT1.IDbCommand.Parameters.Add(  dsDefault.GetDbParameter( "@ClienteGender", System.Data.DbType.Int16));
            cmCLIENTEINSERT1.IDbCommand.Parameters.Add(  dsDefault.GetDbParameter( "@ClienteAge", System.Data.DbType.Int16));
            cmCLIENTEINSERT1.IDbCommand.Parameters.Add(  dsDefault.GetDbParameter( "@ClienteBirthday", System.Data.DbType.Date));
            cmCLIENTEINSERT1.IDbCommand.Parameters.Add(  dsDefault.GetDbParameter( "@ClienteIsActive", System.Data.DbType.Boolean));
            cmCLIENTEINSERT1.IDbCommand.Parameters.Add(  dsDefault.GetDbParameter( "@ClientePicture", System.Data.DbType.Binary));
            cmCLIENTEINSERT1.IDbCommand.Parameters.Add(  dsDefault.GetDbParameter( "@PaisId", System.Data.DbType.Int16));
         }
         cmCLIENTEINSERT1.ErrorMask = cmCLIENTEINSERT1.ErrorMask  |  ErrorMask.DuplicateKeyError;
         cmCLIENTEINSERT1.SetParameter(0, rowCliente["ClienteName"]);
         cmCLIENTEINSERT1.SetParameter(1, rowCliente["ClienteGender"]);
         cmCLIENTEINSERT1.SetParameter(2, rowCliente["ClienteAge"]);
         cmCLIENTEINSERT1.SetParameterDateObject(3, rowCliente["ClienteBirthday"]);
         cmCLIENTEINSERT1.SetParameter(4, rowCliente["ClienteIsActive"]);
         cmCLIENTEINSERT1.SetParameter(5, rowCliente["ClientePicture"]);
         cmCLIENTEINSERT1.SetParameter(6, rowCliente["PaisId"]);
         CLIENTEINSERT1 = cmCLIENTEINSERT1.FetchData() ;
         rowCliente.ClienteId = (short)(CLIENTEINSERT1.GetDecimal(0)) ;
         CLIENTEINSERT1.Close();
         // Start of After( Insert) rules
         // End of After( Insert) rules
         OnClienteUpdated( new ClienteEventArgs( rowCliente, Mode.Insert)) ;
         // Save values for previous() function.
         EndLevelCliente( ) ;
      }

      private void UpdateCliente( )
      {
          ReadWriteCommand cmCLIENTEUPDATE1 ;
         CheckExtendedTableCliente( ) ;
         CheckOptimisticConcurrencyCliente( ) ;
         AfterConfirmCliente( ) ;
         cmCLIENTEUPDATE1 = connDefault.GetCommand("UPDATE [Cliente] SET [ClienteName]=@ClienteName, [ClienteGender]=@ClienteGender, [ClienteAge]=@ClienteAge, [ClienteBirthday]=@ClienteBirthday, [ClienteIsActive]=@ClienteIsActive, [ClientePicture]=@ClientePicture, [PaisId]=@PaisId  WHERE [ClienteId] = @ClienteId", false) ;
         if ( cmCLIENTEUPDATE1.IDbCommand.Parameters.Count == 0 )
         {
            cmCLIENTEUPDATE1.IDbCommand.Parameters.Add(  dsDefault.GetDbParameter( "@ClienteName", System.Data.DbType.AnsiStringFixedLength,20));
            cmCLIENTEUPDATE1.IDbCommand.Parameters.Add(  dsDefault.GetDbParameter( "@ClienteGender", System.Data.DbType.Int16));
            cmCLIENTEUPDATE1.IDbCommand.Parameters.Add(  dsDefault.GetDbParameter( "@ClienteAge", System.Data.DbType.Int16));
            cmCLIENTEUPDATE1.IDbCommand.Parameters.Add(  dsDefault.GetDbParameter( "@ClienteBirthday", System.Data.DbType.Date));
            cmCLIENTEUPDATE1.IDbCommand.Parameters.Add(  dsDefault.GetDbParameter( "@ClienteIsActive", System.Data.DbType.Boolean));
            cmCLIENTEUPDATE1.IDbCommand.Parameters.Add(  dsDefault.GetDbParameter( "@ClientePicture", System.Data.DbType.Binary));
            cmCLIENTEUPDATE1.IDbCommand.Parameters.Add(  dsDefault.GetDbParameter( "@PaisId", System.Data.DbType.Int16));
            cmCLIENTEUPDATE1.IDbCommand.Parameters.Add(  dsDefault.GetDbParameter( "@ClienteId", System.Data.DbType.Int16));
         }
         // Using cursor CLIENTEUPDATE1
         cmCLIENTEUPDATE1.SetParameter(0, rowCliente["ClienteName"]);
         cmCLIENTEUPDATE1.SetParameter(1, rowCliente["ClienteGender"]);
         cmCLIENTEUPDATE1.SetParameter(2, rowCliente["ClienteAge"]);
         cmCLIENTEUPDATE1.SetParameterDateObject(3, rowCliente["ClienteBirthday"]);
         cmCLIENTEUPDATE1.SetParameter(4, rowCliente["ClienteIsActive"]);
         cmCLIENTEUPDATE1.SetParameter(5, rowCliente["ClientePicture"]);
         cmCLIENTEUPDATE1.SetParameter(6, rowCliente["PaisId"]);
         cmCLIENTEUPDATE1.SetParameter(7, rowCliente["ClienteId"]);
         cmCLIENTEUPDATE1.ExecuteStmt();
         if ( cmCLIENTEUPDATE1.Locked )
         {
            CLIENTESELECT4.Close();
            throw new ClienteDataLockedException( string.Format(resourceManager.GetString("GXM_lock"), new   object[]  {"Cliente"})) ;
         }
         // Start of After( update) rules
         // End of After( update) rules
         OnClienteUpdated( new ClienteEventArgs( rowCliente, Mode.Update)) ;
         EndLevelCliente( ) ;
      }

      private void Delete( )
      {
          ReadWriteCommand cmCLIENTEDELETE1 ;
         Gx_mode = Mode.Delete ;
         CheckOptimisticConcurrencyCliente( ) ;
         OnDeleteControlsCliente( ) ;
         AfterConfirmCliente( ) ;
         // No cascading delete specified.
         cmCLIENTEDELETE1 = connDefault.GetCommand("DELETE FROM [Cliente]  WHERE [ClienteId] = @ClienteId", false) ;
         if ( cmCLIENTEDELETE1.IDbCommand.Parameters.Count == 0 )
         {
            cmCLIENTEDELETE1.IDbCommand.Parameters.Add(  dsDefault.GetDbParameter( "@ClienteId", System.Data.DbType.Int16));
         }
         cmCLIENTEDELETE1.ErrorMask = cmCLIENTEDELETE1.ErrorMask  |  ErrorMask.ForeignKeyError;
         // Using cursor CLIENTEDELETE1
         cmCLIENTEDELETE1.SetParameter(0, rowCliente["ClienteId"]);
         cmCLIENTEDELETE1.ExecuteStmt();
         if ( cmCLIENTEDELETE1.ForeignKeyError )
         {
            CheckDeleteErrorsCliente( ) ;
         }
         // Start of After( delete) rules
         // End of After( delete) rules
         OnClienteUpdated( new ClienteEventArgs( rowCliente, Mode.Delete)) ;
         rowCliente.Delete( ) ;
         sMode1 = Gx_mode ;
         Gx_mode = Mode.Delete ;
         EndLevelCliente( ) ;
         Gx_mode = sMode1 ;
      }

      private void OnDeleteControlsCliente( )
      {
          IDataReader PAISSELECT3 ;
          ReadWriteCommand cmPAISSELECT3 ;
         // Delete mode formulas
         cmPAISSELECT3 = connDefault.GetCommand("SELECT [PaisNombre] FROM [Pais] WITH (NOLOCK) WHERE [PaisId] = @PaisId ", false) ;
         if ( cmPAISSELECT3.IDbCommand.Parameters.Count == 0 )
         {
            cmPAISSELECT3.IDbCommand.Parameters.Add(  dsDefault.GetDbParameter( "@PaisId", System.Data.DbType.Int16));
         }
         cmPAISSELECT3.SetParameter(0, rowCliente["PaisId"]);
         PAISSELECT3 = cmPAISSELECT3.FetchData() ;
         if ( cmPAISSELECT3.HasMoreRows )
         {
            rowCliente["PaisNombre"] = dsDefault.Db.GetString(PAISSELECT3, 0) ;
         }
         PAISSELECT3.Close();
      }

      private void CheckDeleteErrorsCliente( )
      {
          IDataReader INVOICESELECT1 ;
          ReadWriteCommand cmINVOICESELECT1 ;
         cmINVOICESELECT1 = connDefault.GetCommand("SELECT TOP 1 [InvoiceId] FROM [Invoice] WITH (NOLOCK) WHERE [ClienteId] = @ClienteId ", false) ;
         if ( cmINVOICESELECT1.IDbCommand.Parameters.Count == 0 )
         {
            cmINVOICESELECT1.IDbCommand.Parameters.Add(  dsDefault.GetDbParameter( "@ClienteId", System.Data.DbType.Int16));
         }
         cmINVOICESELECT1.SetParameter(0, rowCliente["ClienteId"]);
         INVOICESELECT1 = cmINVOICESELECT1.FetchData() ;
         if ( cmINVOICESELECT1.HasMoreRows )
         {
            INVOICESELECT1.Close();
            throw new InvoiceInvalidDeleteException( string.Format(resourceManager.GetString("GXM_del"), new   object[]  {"Invoice"})) ;
         }
         INVOICESELECT1.Close();
      }

      private void EndLevelCliente( )
      {
         // Execute 'After Trn' event if defined.
         IsModified = 0 ;
      }

      private void ScanByClienteId( int startRow ,
                                    int maxRows )
      {
         m_WhereString = " WHERE TM1.[ClienteId] = @ClienteId" ;
         if ( maxRows >= 0 )
         {
            if ( startRow == 0 )
            {
               scmdbuf = "SELECT TOP " + maxRows.ToString() + "  " + m_SelectString1 + "  FROM ([Cliente] TM1 WITH (NOLOCK) INNER JOIN [Pais] T2 WITH (NOLOCK) ON T2.[PaisId] = TM1.[PaisId])" + m_WhereString + " ORDER BY TM1.[ClienteId]" ;
            }
            else
            {
               scmdbuf = " SELECT * FROM ( SELECT  " + m_SelectString1 + ", ROW_NUMBER() OVER  (  ORDER BY TM1.[ClienteId] ) AS DK_PAGENUM   FROM ([Cliente] TM1 WITH (NOLOCK) INNER JOIN [Pais] T2 WITH (NOLOCK) ON T2.[PaisId] = TM1.[PaisId]) " + m_WhereString + " ) AS DK_PAGE WHERE DK_PAGENUM BETWEEN " + (startRow + 1).ToString() + " AND " + (startRow + maxRows).ToString() ;
            }
         }
         else
         {
            scmdbuf = "SELECT " + m_SelectString1 + " FROM ([Cliente] TM1 WITH (NOLOCK) INNER JOIN [Pais] T2 WITH (NOLOCK) ON T2.[PaisId] = TM1.[PaisId])" + m_WhereString + " ORDER BY TM1.[ClienteId] " ;
         }
         cmCLIENTESELECT5 = connDefault.GetCommand(scmdbuf, false) ;
         if ( cmCLIENTESELECT5.IDbCommand.Parameters.Count == 0 )
         {
            cmCLIENTESELECT5.IDbCommand.Parameters.Add(  dsDefault.GetDbParameter( "@ClienteId", System.Data.DbType.Int16));
         }
         cmCLIENTESELECT5.SetParameter(0, rowCliente["ClienteId"]);
         CLIENTESELECT5 = cmCLIENTESELECT5.FetchData() ;
         RcdFound1 = 0 ;
         ScanKeyLoadCliente( ) ;
         LoadKeyDataCliente( maxRows) ;
         // Load Subordinate Levels
      }

      private void ScanByPaisId( int startRow ,
                                 int maxRows )
      {
         m_WhereString = " WHERE TM1.[PaisId] = @PaisId" ;
         if ( maxRows >= 0 )
         {
            if ( startRow == 0 )
            {
               scmdbuf = "SELECT TOP " + maxRows.ToString() + "  " + m_SelectString1 + "  FROM ([Cliente] TM1 WITH (NOLOCK) INNER JOIN [Pais] T2 WITH (NOLOCK) ON T2.[PaisId] = TM1.[PaisId])" + m_WhereString + " ORDER BY TM1.[ClienteId]" ;
            }
            else
            {
               scmdbuf = " SELECT * FROM ( SELECT  " + m_SelectString1 + ", ROW_NUMBER() OVER  (  ORDER BY TM1.[ClienteId] ) AS DK_PAGENUM   FROM ([Cliente] TM1 WITH (NOLOCK) INNER JOIN [Pais] T2 WITH (NOLOCK) ON T2.[PaisId] = TM1.[PaisId]) " + m_WhereString + " ) AS DK_PAGE WHERE DK_PAGENUM BETWEEN " + (startRow + 1).ToString() + " AND " + (startRow + maxRows).ToString() ;
            }
         }
         else
         {
            scmdbuf = "SELECT " + m_SelectString1 + " FROM ([Cliente] TM1 WITH (NOLOCK) INNER JOIN [Pais] T2 WITH (NOLOCK) ON T2.[PaisId] = TM1.[PaisId])" + m_WhereString + " ORDER BY TM1.[ClienteId] " ;
         }
         cmCLIENTESELECT5 = connDefault.GetCommand(scmdbuf, false) ;
         if ( cmCLIENTESELECT5.IDbCommand.Parameters.Count == 0 )
         {
            cmCLIENTESELECT5.IDbCommand.Parameters.Add(  dsDefault.GetDbParameter( "@PaisId", System.Data.DbType.Int16));
         }
         cmCLIENTESELECT5.SetParameter(0, rowCliente["PaisId"]);
         CLIENTESELECT5 = cmCLIENTESELECT5.FetchData() ;
         RcdFound1 = 0 ;
         ScanKeyLoadCliente( ) ;
         LoadKeyDataCliente( maxRows) ;
         // Load Subordinate Levels
      }

      private void ScanKeyStartCliente( int startRow ,
                                        int maxRows )
      {
         m_WhereString = "" ;
         if ( maxRows >= 0 )
         {
            if ( startRow == 0 )
            {
               scmdbuf = "SELECT TOP " + maxRows.ToString() + "  " + m_SelectString1 + "  FROM ([Cliente] TM1 WITH (NOLOCK) INNER JOIN [Pais] T2 WITH (NOLOCK) ON T2.[PaisId] = TM1.[PaisId])" + m_WhereString + " ORDER BY TM1.[ClienteId]" ;
            }
            else
            {
               scmdbuf = " SELECT * FROM ( SELECT  " + m_SelectString1 + ", ROW_NUMBER() OVER  (  ORDER BY TM1.[ClienteId] ) AS DK_PAGENUM   FROM ([Cliente] TM1 WITH (NOLOCK) INNER JOIN [Pais] T2 WITH (NOLOCK) ON T2.[PaisId] = TM1.[PaisId]) " + m_WhereString + " ) AS DK_PAGE WHERE DK_PAGENUM BETWEEN " + (startRow + 1).ToString() + " AND " + (startRow + maxRows).ToString() ;
            }
         }
         else
         {
            scmdbuf = "SELECT " + m_SelectString1 + " FROM ([Cliente] TM1 WITH (NOLOCK) INNER JOIN [Pais] T2 WITH (NOLOCK) ON T2.[PaisId] = TM1.[PaisId])" + m_WhereString + " ORDER BY TM1.[ClienteId] " ;
         }
         cmCLIENTESELECT5 = connDefault.GetCommand(scmdbuf, false) ;
         CLIENTESELECT5 = cmCLIENTESELECT5.FetchData() ;
         RcdFound1 = 0 ;
         ScanKeyLoadCliente( ) ;
         LoadKeyDataCliente( maxRows) ;
         // Load Subordinate Levels
      }

      private void ScanKeyNextCliente( )
      {
         cmCLIENTESELECT5.HasMoreRows = CLIENTESELECT5.Read() ;
         RcdFound1 = 0 ;
         ScanKeyLoadCliente( ) ;
      }

      private void ScanKeyLoadCliente( )
      {
         sMode1 = Gx_mode ;
         Gx_mode = Mode.Display ;
         if ( cmCLIENTESELECT5.HasMoreRows )
         {
            RcdFound1 = 1 ;
            rowCliente["ClienteId"] = dsDefault.Db.GetInt16(CLIENTESELECT5, 0) ;
            rowCliente["ClienteName"] = dsDefault.Db.GetString(CLIENTESELECT5, 1) ;
            rowCliente["ClienteGender"] = dsDefault.Db.GetInt16(CLIENTESELECT5, 2) ;
            rowCliente["ClienteAge"] = dsDefault.Db.GetInt16(CLIENTESELECT5, 3) ;
            rowCliente["ClienteBirthday"] = dsDefault.Db.GetDateTime(CLIENTESELECT5, 4) ;
            rowCliente["ClienteIsActive"] = dsDefault.Db.GetBoolean(CLIENTESELECT5, 5) ;
            rowCliente["PaisNombre"] = dsDefault.Db.GetString(CLIENTESELECT5, 6) ;
            rowCliente["PaisId"] = dsDefault.Db.GetInt16(CLIENTESELECT5, 7) ;
            rowCliente["ClientePicture"] = dsDefault.Db.GetBinary(CLIENTESELECT5, 8) ;
            rowCliente["PaisNombre"] = dsDefault.Db.GetString(CLIENTESELECT5, 6) ;
         }
         Gx_mode = sMode1 ;
      }

      private void ScanKeyEndCliente( )
      {
         CLIENTESELECT5.Close();
      }

      private void AfterConfirmCliente( )
      {
         // After Confirm Rules
         OnClienteUpdating( new ClienteEventArgs( rowCliente, Gx_mode)) ;
      }

      private void CreateNewRowCliente( )
      {
         rowCliente = ClienteSet.Cliente.NewClienteRow() ;
      }

      private void LoadChildCliente( int startRow ,
                                     int maxRows )
      {
         CreateNewRowCliente( ) ;
         bool tmpConstraintState = ClienteSet.EnforceConstraints ;
         ClienteSet.Cliente.BeginLoadData( ) ;
         ScanKeyStartCliente( startRow, maxRows) ;
         ClienteSet.Cliente.EndLoadData( ) ;
         this.ClienteSet.EnforceConstraints = tmpConstraintState ;
      }

      private void LoadKeyDataCliente( int maxRows )
      {
         int loadedRows = 0 ;
         if ( RcdFound1 != 0 )
         {
            ScanKeyLoadCliente( ) ;
            while ( ( RcdFound1 != 0 ) && ( loadedRows != maxRows ) )
            {
               loadedRows++ ;
               LoadRowCliente( ) ;
               CreateNewRowCliente( ) ;
               ScanKeyNextCliente( ) ;
            }
         }
         if ( loadedRows > 0 )
         {
            RcdFound1 = 1 ;
         }
         ScanKeyEndCliente( ) ;
         if ( ClienteSet.Cliente.Count > 0 )
         {
            rowCliente = ClienteSet.Cliente[ClienteSet.Cliente.Count -1] ;
         }
      }

      private void LoadByClienteId( int startRow ,
                                    int maxRows )
      {
         bool tmpConstraintState = ClienteSet.EnforceConstraints ;
         ClienteSet.Cliente.BeginLoadData( ) ;
         ScanByClienteId( startRow, maxRows) ;
         ClienteSet.Cliente.EndLoadData( ) ;
         this.ClienteSet.EnforceConstraints = tmpConstraintState ;
         if ( ClienteSet.Cliente.Count > 0 )
         {
            rowCliente = ClienteSet.Cliente[ClienteSet.Cliente.Count -1] ;
         }
      }

      private void LoadByPaisId( int startRow ,
                                 int maxRows )
      {
         bool tmpConstraintState = ClienteSet.EnforceConstraints ;
         ClienteSet.Cliente.BeginLoadData( ) ;
         ScanByPaisId( startRow, maxRows) ;
         ClienteSet.Cliente.EndLoadData( ) ;
         this.ClienteSet.EnforceConstraints = tmpConstraintState ;
         if ( ClienteSet.Cliente.Count > 0 )
         {
            rowCliente = ClienteSet.Cliente[ClienteSet.Cliente.Count -1] ;
         }
      }

      private void AddRowCliente( )
      {
         ClienteSet.Cliente.AddClienteRow( rowCliente) ;
      }

      private readonly string m_SelectString1 = "TM1.[ClienteId], TM1.[ClienteName], TM1.[ClienteGender], TM1.[ClienteAge], TM1.[ClienteBirthday], TM1.[ClienteIsActive], T2.[PaisNombre], TM1.[PaisId], TM1.[ClientePicture]" ;


      public delegate  void ClienteUpdateEventHandler( object sender ,
                                                       ClienteEventArgs e );
      public event ClienteUpdateEventHandler ClienteUpdated ;
      private void OnClienteUpdated( ClienteEventArgs e )
      {
         if ( this.ClienteUpdated != null )
         {
            this.ClienteUpdated( this, e) ;
         }
      }

      public event ClienteUpdateEventHandler ClienteUpdating ;
      private void OnClienteUpdating( ClienteEventArgs e )
      {
         if ( this.ClienteUpdating != null )
         {
            this.ClienteUpdating( this, e) ;
         }
      }

      public class ClienteEventArgs : EventArgs
      {
         private System.Data.StatementType m_statementType ;
         private ClienteDataSet.ClienteRow m_dataRow ;
         public ClienteEventArgs( ClienteDataSet.ClienteRow row ,
                                  StatementType statementType )
         {
            m_dataRow = row ;
            m_statementType = statementType ;
         }

         public System.Data.StatementType StatementType
         {
            get {
               return m_statementType ;
            }

         }

         public ClienteDataSet.ClienteRow Row
         {
            get {
               return m_dataRow ;
            }

            set {
               m_dataRow = value ;
            }

         }

      }


      // Custom Exceptions
      [Serializable()]
      public class ClienteNotFoundException : Deklarit.DataNotFoundException
      {
         public ClienteNotFoundException( )
         {
         }

         public ClienteNotFoundException( string message ) : base(message)
         {
         }

         public ClienteNotFoundException( string message ,
                                          Exception inner ) : base(message, inner)
         {
         }

         protected ClienteNotFoundException( SerializationInfo info ,
                                             StreamingContext context ) : base(info, context)
         {
         }

      }

      [Serializable()]
      public class ClienteGenderInvalidValue : Deklarit.UserException
      {
         public ClienteGenderInvalidValue( )
         {
         }

         public ClienteGenderInvalidValue( string message ) : base(message)
         {
         }

         public ClienteGenderInvalidValue( string message ,
                                           Exception inner ) : base(message, inner)
         {
         }

         protected ClienteGenderInvalidValue( SerializationInfo info ,
                                              StreamingContext context ) : base(info, context)
         {
         }

      }

      [Serializable()]
      public class PaisForeignKeyNotFoundException : Deklarit.ForeignKeyNotFoundException
      {
         public PaisForeignKeyNotFoundException( )
         {
         }

         public PaisForeignKeyNotFoundException( string message ) : base(message)
         {
         }

         public PaisForeignKeyNotFoundException( string message ,
                                                 Exception inner ) : base(message, inner)
         {
         }

         protected PaisForeignKeyNotFoundException( SerializationInfo info ,
                                                    StreamingContext context ) : base(info, context)
         {
         }

      }

      [Serializable()]
      public class ClienteDataLockedException : Deklarit.DataLockedException
      {
         public ClienteDataLockedException( )
         {
         }

         public ClienteDataLockedException( string message ) : base(message)
         {
         }

         public ClienteDataLockedException( string message ,
                                            Exception inner ) : base(message, inner)
         {
         }

         protected ClienteDataLockedException( SerializationInfo info ,
                                               StreamingContext context ) : base(info, context)
         {
         }

      }

      [Serializable()]
      public class ClienteDataChangedException : Deklarit.DataChangedException
      {
         public ClienteDataChangedException( )
         {
         }

         public ClienteDataChangedException( string message ) : base(message)
         {
         }

         public ClienteDataChangedException( string message ,
                                             Exception inner ) : base(message, inner)
         {
         }

         protected ClienteDataChangedException( SerializationInfo info ,
                                                StreamingContext context ) : base(info, context)
         {
         }

      }

      [Serializable()]
      public class InvoiceInvalidDeleteException : Deklarit.InvalidDeleteException
      {
         public InvoiceInvalidDeleteException( )
         {
         }

         public InvoiceInvalidDeleteException( string message ) : base(message)
         {
         }

         public InvoiceInvalidDeleteException( string message ,
                                               Exception inner ) : base(message, inner)
         {
         }

         protected InvoiceInvalidDeleteException( SerializationInfo info ,
                                                  StreamingContext context ) : base(info, context)
         {
         }

      }


      protected void Cleanup( )
      {
         dsDefault.Dispose();
      }


      private void Initialize( )
      {
         resourceManager = Deklarit.Utils.ResourceManager.Instance ;
         resourceManagerTables = new System.Resources.ResourceManager( "Deklarit.Tables", System.Reflection.Assembly.GetExecutingAssembly()) ;
         scmdbuf = "" ;
         m__ClienteNameOriginal = new object();
         m__ClienteGenderOriginal = new object();
         m__ClienteAgeOriginal = new object();
         m__ClienteBirthdayOriginal = new object();
         m__ClienteIsActiveOriginal = new object();
         m__ClientePictureOriginal = new object();
         m__PaisIdOriginal = new object();
         m_WhereString = "" ;
         if ( this.Transaction == null )
         {
            this.Transaction = ((System.Data.IDbTransaction)(System.Threading.Thread.GetData(System.Threading.Thread.GetNamedDataSlot(DeklaritTransaction.TransactionSlotName)) ));
         }
      }

      private short RcdFound1 ;
      private short IsModified ;
      private int recordCount ;
      private String scmdbuf ;
      private String m_WhereString ;
      private bool _Gxremove ;
      private bool _Condition ;
      private DataStore dsDefault ;
      private System.Resources.ResourceManager resourceManager ;
      private System.Resources.ResourceManager resourceManagerTables ;
      private ReadWriteConnection connDefault ;
      private ReadWriteCommand cmCLIENTESELECT1 ;
      private IDataReader CLIENTESELECT1 ;
      private ReadWriteCommand cmCLIENTESELECT2 ;
      private IDataReader CLIENTESELECT2 ;
      private object m__ClienteNameOriginal ;
      private object m__ClienteGenderOriginal ;
      private object m__ClienteAgeOriginal ;
      private object m__ClienteBirthdayOriginal ;
      private object m__ClienteIsActiveOriginal ;
      private object m__ClientePictureOriginal ;
      private object m__PaisIdOriginal ;
      private IDataReader CLIENTESELECT4 ;
      private ReadWriteCommand cmCLIENTESELECT5 ;
      private IDataReader CLIENTESELECT5 ;
      private System.Data.StatementType Gx_mode ;
      private System.Data.StatementType sMode1 ;
   }

   public class ClienteDataReader : System.IDisposable
   {
      public ClienteDataReader( )
      {
      }

      private void init_reader( )
      {
         this.Initialize( ) ;
         dsDefault = new DataStore( new SqlServer2005Handler( ), "System.Data.SqlClient", DeklaritModel.Configuration.ConnectionString, DeklaritTransaction.TransactionSlotName) ;
         m_Disposed = false ;
         m_Closed = true ;
      }

      private IDbTransaction daCurrentTransaction ;
      ///  <summary>
      ///   Gets or sets the Transaction object to be used  by  ClienteDataReaderDeklarit DataReaderclasses
      ///    to commit changes to the Database.
      ///  </summary>
      public IDbTransaction Transaction
      {
         get {
            return daCurrentTransaction ;
         }

         set {
            daCurrentTransaction = value ;
         }

      }

      public IDataReader Open( )
      {
         init_reader( ) ;
         m_Closed = false ;
         connDefault = dsDefault.GetReadWriteConnection( daCurrentTransaction) ;
         cmCLIENTESELECT6 = connDefault.GetCommand("SELECT TM1.[ClienteId], TM1.[ClienteName], TM1.[ClienteGender], TM1.[ClienteAge], TM1.[ClienteBirthday], TM1.[ClienteIsActive], T2.[PaisNombre], TM1.[PaisId], TM1.[ClientePicture] FROM ([Cliente] TM1 LEFT JOIN [Pais] T2 ON T2.[PaisId] = TM1.[PaisId]) ORDER BY TM1.[ClienteId] ", false) ;
         CLIENTESELECT6 = cmCLIENTESELECT6.ExecuteReader(((daCurrentTransaction==null) ? Configuration.ReaderCommandBehavior : CommandBehavior.Default)) ;
         return CLIENTESELECT6 ;
      }

      public IDataReader OpenByClienteId( short clienteId )
      {
         init_reader( ) ;
         m_Closed = false ;
         connDefault = dsDefault.GetReadWriteConnection( daCurrentTransaction) ;
         cmCLIENTESELECT6 = connDefault.GetCommand("SELECT TM1.[ClienteId], TM1.[ClienteName], TM1.[ClienteGender], TM1.[ClienteAge], TM1.[ClienteBirthday], TM1.[ClienteIsActive], T2.[PaisNombre], TM1.[PaisId], TM1.[ClientePicture] FROM ([Cliente] TM1 LEFT JOIN [Pais] T2 ON T2.[PaisId] = TM1.[PaisId]) WHERE TM1.[ClienteId] = @ClienteId ORDER BY TM1.[ClienteId] ", false) ;
         if ( cmCLIENTESELECT6.IDbCommand.Parameters.Count == 0 )
         {
            cmCLIENTESELECT6.IDbCommand.Parameters.Add(  dsDefault.GetDbParameter( "@ClienteId", System.Data.DbType.Int16));
         }
         cmCLIENTESELECT6.SetParameter(0, clienteId);
         CLIENTESELECT6 = cmCLIENTESELECT6.ExecuteReader(((daCurrentTransaction==null) ? Configuration.ReaderCommandBehavior : CommandBehavior.Default)) ;
         return CLIENTESELECT6 ;
      }

      public IDataReader OpenByPaisId( short paisId )
      {
         init_reader( ) ;
         m_Closed = false ;
         connDefault = dsDefault.GetReadWriteConnection( daCurrentTransaction) ;
         cmCLIENTESELECT6 = connDefault.GetCommand("SELECT TM1.[ClienteId], TM1.[ClienteName], TM1.[ClienteGender], TM1.[ClienteAge], TM1.[ClienteBirthday], TM1.[ClienteIsActive], T2.[PaisNombre], TM1.[PaisId], TM1.[ClientePicture] FROM ([Cliente] TM1 LEFT JOIN [Pais] T2 ON T2.[PaisId] = TM1.[PaisId]) WHERE TM1.[PaisId] = @PaisId ORDER BY TM1.[ClienteId] ", false) ;
         if ( cmCLIENTESELECT6.IDbCommand.Parameters.Count == 0 )
         {
            cmCLIENTESELECT6.IDbCommand.Parameters.Add(  dsDefault.GetDbParameter( "@PaisId", System.Data.DbType.Int16));
         }
         cmCLIENTESELECT6.SetParameter(0, paisId);
         CLIENTESELECT6 = cmCLIENTESELECT6.ExecuteReader(((daCurrentTransaction==null) ? Configuration.ReaderCommandBehavior : CommandBehavior.Default)) ;
         return CLIENTESELECT6 ;
      }

      public int DeleteByPaisId( short paisId )
      {
         init_reader( ) ;
         int intCount = 0 ;
         connDefault = dsDefault.GetReadWriteConnection( daCurrentTransaction) ;
         cmCLIENTEDELETE2 = connDefault.GetCommand("DELETE FROM [Cliente]  WHERE [PaisId] = @PaisId", false) ;
         if ( cmCLIENTEDELETE2.IDbCommand.Parameters.Count == 0 )
         {
            cmCLIENTEDELETE2.IDbCommand.Parameters.Add(  dsDefault.GetDbParameter( "@PaisId", System.Data.DbType.Int16));
         }
         // Using cursor CLIENTEDELETE2
         cmCLIENTEDELETE2.SetParameter(0, paisId);
         intCount = cmCLIENTEDELETE2.ExecuteStmt() ;
         return intCount ;
      }

      public void Dispose( )
      {
         if ( ! m_Disposed )
         {
            m_Disposed = true ;
            try
            {
               if ( ! m_Closed && ( CLIENTESELECT6 != null ) )
               {
                  m_Closed = true ;
                  CLIENTESELECT6.Close();
               }
            }
            finally
            {
               try
               {
                  connDefault.Close();
               }
               finally
               {
                  this.Cleanup();
               }
            }
         }
      }

      public void Close( )
      {
         this.Dispose( ) ;
      }


      protected void Cleanup( )
      {
         dsDefault.Dispose();
      }


      private void Initialize( )
      {
         scmdbuf = "" ;
         if ( this.Transaction == null )
         {
            this.Transaction = ((System.Data.IDbTransaction)(System.Threading.Thread.GetData(System.Threading.Thread.GetNamedDataSlot(DeklaritTransaction.TransactionSlotName)) ));
         }
      }

      private String scmdbuf ;
      private bool m_Disposed ;
      private bool m_Closed ;
      private DataStore dsDefault ;
      private ReadWriteConnection connDefault ;
      private ReadWriteCommand cmCLIENTESELECT6 ;
      private IDataReader CLIENTESELECT6 ;
      private ReadWriteCommand cmCLIENTEDELETE2 ;
   }

}
